﻿using System;

namespace MySql.Simple.Mapper.Structures
{
    /// <summary>
    /// Represents an Index on an underlying database table.
    /// </summary>
    public class Index
    {
        private string name;

        /// <summary>
        /// Gets or sets the table.
        /// </summary>
        /// <value>The table.</value>
        public string Table { get; set; }

        /// <summary>
        /// Gets or sets the column.
        /// </summary>
        /// <value>The column.</value>
        public string Column { get; set; }

        /// <summary>
        /// Gets or sets the type of the index.
        /// </summary>
        /// <value>The type of the index.</value>
        public IndexType IndexType { get; set; }

        /// <summary>
        /// Gets or sets the length of the contents of the column
        /// to index.
        /// </summary>
        /// <value>The length.</value>
        public int Length { get; set; }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        public string Name
        {
            get
            {
                if (string.IsNullOrEmpty(name)) name = Column + "_index_" + Id;

                return name;
            }
            set { name = value; }
        }

        /// <summary>
        /// Gets or sets the id of the index.
        /// </summary>
        /// <value>The id.</value>
        public int Id { get; set; }
    }
}
